<template>
  <div id="reportAudit">
    <el-card class="box-card" style="margin:15px">
      <el-form
        ref="basicForm"
        :inline="true"
        :model="basicData.model"
        :rules="basicDataRules"
        class="demo-form-inline"
        size="small"
        label-width="120px"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="所属区县:" prop="areaId.key" width="300px">
              <el-select
                size="mini"
                v-model="basicData.model.areaId.key"
                placeholder="选择"
                @change="clickOrgTree"
              >
                <el-option
                  v-for="(item, index) in orgTree"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                  width="300px"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属医院:" prop="hospitalId.key">
              <el-select
                size="mini"
                v-model="basicData.model.hospitalId.key"
                placeholder="选择"
                @change="clickOrgTreeC"
              >
                <el-option
                  v-for="(item, index) in orgTreeC"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属部门:" prop="departId.key" class="info-item">
              <el-select size="mini" v-model="basicData.model.departId.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in orgTreeCs"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="实验项目:" prop="experimentCode.key" class="projectIdList">
              <el-select size="mini" v-model="basicData.model.experimentCode.key">
                <el-option
                  v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
                  :key="index"
                  :label="item"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="母亲姓名:" prop="momName">
              <el-input
                @keyup.enter.native="getList(basicData)"
                size="mini"
                v-model="basicData.model.momName"
                placeholder="输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号码:" prop="phone" class="info-item">
              <el-input size="mini" v-model="basicData.model.phone" placeholder="输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display:flex;align-items: center;">
          <el-col :span="6">
            <el-form-item label="实验编码:" class="projectIdList">
              <div style="display:flex">
                <el-input
                  size="mini"
                  v-model="basicData.model.expNum.start"
                  placeholder="输入"
                  style="width:50%"
                />
                <span>-</span>
                <el-input
                  size="mini"
                  v-model="basicData.model.expNum.end"
                  placeholder="输入"
                  style="width:50%"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="time-list">
            <div style="display:flex">
              <el-select
                size="mini"
                style="width:140px !important;margin-left:1.5vw"
                slot="prepend"
                v-model="timeType"
                placeholder="出生日期"
              >
                <el-option label="出生日期" value="birthTime" />
                <el-option label="实验日期" value="experimentDate" />
              </el-select>
              <el-date-picker
                size="mini"
                v-model="dateList"
                style="width:100%"
                type="daterange"
                range-separator="至"
                value-format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </div>
          </el-col>
        </el-row>
      </el-form>
      <div class="buttom">
        <el-button type="primary" size="mini" icon="el-icon-search" @click="onSubmit('query')">查询</el-button>
        <el-button size="small" @click="onSubmit('reset')">重置</el-button>
      </div>
    </el-card>
    <el-card class="box-card" style="margin:15px">
      <div style="margin-bottom:10px;display:flex">
        <el-button size="small" type="primary" icon="el-icon-tickets" @click="clickAudit">审核</el-button>
        <el-button size="small" @click="clickEdit" v-loading="editSempelLoading">修改样本</el-button>
        <el-button size="small" @click="syncReport">更新报告</el-button>
        <el-button size="small" type="primary" icon="el-icon-tickets" @click="getList(basicData)">刷新</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
        @selection-change="selectChanage"
      >
        <el-table-column align="center" type="selection" width="45" />
        <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
        <el-table-column align="center" prop="momName" label="母亲姓名" />
        <el-table-column align="center" prop="phone" label="手机号码" />
        <el-table-column align="center" prop="birthTime" label="出生日期" />
        <el-table-column align="center" prop="babySex.data" label="性别" />
        <el-table-column align="center" prop="hospitalId.data.label" label="所属医院" />
        <el-table-column align="center" prop="experimentCode.data" label="实验项目" />
        <!-- <el-table-column align="center" prop="experimentResult.data" label="实验结论" /> -->
        <!-- <el-table-column align="center" prop="experimentValue" label="实验结果">
          <template slot-scope="scope">
            <span
              style="color: #1890ff;cursor: pointer;"
              @click="clickSeeExpValue(scope.row.experimentValue)"
            >点击查看</span>
          </template>
        </el-table-column>-->
      </el-table>
      <el-pagination
        :current-page="basicData.current"
        :page-size="basicData.size"
        :total="total"
        layout="slot, total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <span
          v-if="tableData.length > 0"
          style="font-weight: 400;color:#606266"
        >已选中{{ selectList.length }}条，</span>
      </el-pagination>
    </el-card>

    <!-- 审核 -->
    <el-dialog
      width="85%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :title="auditTitle"
      :visible.sync="auditShow"
      append-to-body
    >
      <el-form ref="projectManageForm" :model="auditFormData" label-width="120px" size="small">
        <el-row style="margin-bottom:10px !important">
          <el-col :span="6">
            <el-form-item label="实验编号:">
              <el-input size="mini" v-model="queryData.expNum" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="母亲姓名:">
              <el-input size="mini" v-model="queryData.momName" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="实验结果:">
              <el-select v-model="queryData.experimentValueResult.key">
                <el-option
                  :label="item"
                  :value="key"
                  v-for="(item, key, index) in dicts.EXPERIMENT_RESULT"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-button
              size="mini"
              type="primary"
              @click="clickResult"
              style="margin-left:15px  !important;"
            >重置</el-button>
          </el-col>
        </el-row>
        <el-row>
          <el-table
            ref="dormitoryTable"
            row-key="sampleId"
            :data="tables"
            stripe
            style="width: 100%;"
            :header-cell-style="{
              background: '#333333',
              color: '#ffffff',
              textAlign: 'center'
            }"
            class="import-table"
            @selection-change="selectAuditListChanage"
            :cell-style="tableRowStyle"
          >
            <!-- <el-table-column align="center" type="selection" width="45" /> -->
            <el-table-column align="center" type="index" width="65" />
            <el-table-column align="center" label="实验编号" width="150" prop="expNum" />
            <el-table-column align="center" label="条形码号" width="150" prop="barCode" />
            <el-table-column align="center" label="采血日期" width="100" prop="bloodTime">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.bloodTime ? scope.row.bloodTime.substr(0, 10) : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="母亲姓名" prop="momName" />
            <el-table-column align="center" label="性别" prop="babySex.data" />
            <el-table-column align="center" label="出生日期" width="100" prop="birthTime">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.birthTime ? scope.row.birthTime.substr(0, 10) : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="所属医院"
              prop="hospitalId.data.label"
              show-overflow-tooltip
            />
            <el-table-column align="center" label="实验项目" prop="experimentCode.data" />
            <el-table-column align="center" label="实验日期" width="100" prop="experimentDate">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.experimentDate
                  ? scope.row.experimentDate.substr(0, 10)
                  : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="实验结果" prop="experimentValueResult.data" />
            <el-table-column align="center" label="实验数据" prop="experimentValue">
              <template slot-scope="scope">
                <span
                  style="color: #1890ff;cursor: pointer;"
                  @click="clickSeeExpValue(scope.row.experimentValue)"
                >点击查看</span>
              </template>
            </el-table-column>
            <el-table-column align="center" label="实验结论" prop="experimentResult.key">
              <template slot-scope="scope">
                <el-select
                  size="mini"
                  v-model="scope.row.experimentResult.key"
                  @change="tijiaoList[scope.$index].experimentResult.key = scope.row.experimentResult.key"
                  placeholder="实验结论"
                >
                  <el-option
                    v-for="(item, key, index) in dicts.EXPERIMENT_RESULT"
                    :key="index"
                    :label="item"
                    :value="key"
                  />
                </el-select>
              </template>
            </el-table-column>
          </el-table>

          <el-row v-if="auditTitle == '审核'">
            <el-col :span="8">
              <el-form-item label="实验者:" prop="experimentResultMan">
                <el-input
                  size="mini"
                  style="width:300px"
                  v-model="auditFormData.experimentResultMan"
                  placeholder="输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审核者:" prop="experimentCheckMan">
                <el-input
                  size="mini"
                  style="width:300px"
                  v-model="auditFormData.experimentCheckMan"
                  placeholder="输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="报告者:" prop="experimentReportMan">
                <el-input
                  size="mini"
                  style="width:300px"
                  v-model="auditFormData.experimentReportMan"
                  placeholder="输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="实验日期:" prop="experimentResultTime">
                <el-date-picker
                  size="mini"
                  v-model="auditFormData.experimentResultTime"
                  type="date"
                  style="width:300px"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审核日期:" prop="experimentCheckTime">
                <el-date-picker
                  size="mini"
                  v-model="auditFormData.experimentCheckTime"
                  type="date"
                  style="width:300px"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="报告日期:" prop="experimentReportTime">
                <el-date-picker
                  size="mini"
                  v-model="auditFormData.experimentReportTime"
                  type="date"
                  style="width:300px"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-col :span="24">
            <div style="display:flex;widht:100%;justify-content: center;margin-top:10px">
              <el-button size="small" type="primary" @click="clickAuditSeav">保存</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 点击查看 -->
    <el-dialog width="65%" title="实验数据" :visible.sync="seeShow" append-to-body>
      <!-- 表格 -->
      <el-row style="line-height: 1.5;border:1px solid">
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >筛查项目</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测指标</el-col>
        <el-col
          :span="3"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >检测值</el-col>
        <el-col
          :span="5"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
        >正常参考值</el-col>
        <el-col
          :span="8"
          style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;"
        >筛查结果</el-col>
        <!-- hint -->
      </el-row>
      <!-- 表格内容 -->
      <el-row
        style="line-height: 1.5;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;"
      >
        <div v-for="(item, index) in seeData" :key="index">
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCodeName }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.indicatorCode }}&nbsp</el-col>
          <el-col
            :span="3"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.experimentValue }}{{ item.units }}&nbsp</el-col>
          <el-col
            :span="5"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.referenceValue }}&nbsp</el-col>
          <el-col
            :span="8"
            :style="item.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
            style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
          >{{ item.hint }}&nbsp</el-col>
        </div>
      </el-row>
    </el-dialog>

    <!-- 修改 -->
    <el-dialog :visible.sync="dialogEdit" width="85%" center custom-class="print-dialog">
      <span
        slot="title"
        class="dialog-title"
        style="font-size: 18px;font-weight: 400;color: #FFFFFF;"
      >修改样本</span>

      <el-form
        ref="editForm"
        :rules="editRules"
        :inline="true"
        :model="selectItem"
        class="demo-form-inline"
        label-width="120px"
        size="small"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="所属区县:" prop="areaId.key">
              <el-select
                size="mini"
                v-model="selectItem.areaId.key"
                placeholder="选择"
                @change="clickOrgTree"
              >
                <el-option
                  v-for="(item, index) in orgTree"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属医院:" prop="hospitalId.key">
              <el-select
                size="mini"
                v-model="selectItem.hospitalId.key"
                placeholder="选择"
                @change="clickOrgTreeC"
              >
                <el-option
                  v-for="(item, index) in orgTreeC"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="所属部门:" prop="departId.key">
              <el-select size="mini" v-model="selectItem.departId.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in orgTreeCs"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="母亲姓名:" prop="momName">
              <el-input size="mini" v-model="selectItem.momName" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="母亲身份证:" prop="momCard">
              <el-input size="mini" v-model="selectItem.momCard" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="父亲身份证:" prop="dadCard">
              <el-input size="mini" v-model="selectItem.dadCard" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号码:" prop="phone">
              <el-input
                size="mini"
                v-model="selectItem.phone"
                placeholder="输入"
                type="text"
                maxlength="11"
                oninput="value=value.replace(/[^\d.]/g,'')"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="母亲户籍:" prop="momCensus" v-if="selectItem.momCensus">
              <el-radio-group v-model="selectItem.momCensus.key">
                <el-radio
                  v-for="(item, key, index) in dicts.MOM_CENSUS"
                  :key="item"
                  :label="key"
                >{{ item }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="住址:" prop="address">
              <el-input size="mini" v-model="selectItem.address" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="婴儿体重:" prop="weight">
              <el-input
                size="mini"
                v-model="selectItem.weight"
                type="text"
                oninput="value=value.replace(/[^\d.]/g,'')"
                placeholder="输入"
              >
                <template slot="append">克</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="孕周:" prop="weeks">
              <el-input
                size="mini"
                v-model="selectItem.weeks"
                type="text"
                oninput="value=value.replace(/[^\d.]/g,'')"
                placeholder="输入"
              >
                <template slot="append">周</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="孕天:" prop="days">
              <el-input
                size="mini"
                v-model="selectItem.days"
                placeholder="输入"
                type="text"
                oninput="value=value.replace(/[^\d.]/g,'')"
              >
                <template slot="append">天</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="出生日期:" prop="birthTime">
              <el-date-picker
                size="mini"
                v-model="selectItem.birthTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="户口类型:" prop="accountType" v-if="selectItem.accountType">
              <el-radio-group v-model="selectItem.accountType.key">
                <el-radio
                  v-for="(item, key, index) in dicts.ACCOUNT_TYPE"
                  :key="item"
                  :label="key"
                >{{ item }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="性别:" prop="babySex">
              <el-radio-group v-model="selectItem.babySex.key">
                <el-radio
                  v-for="(item, key, index) in dicts.BABY_SEX"
                  :key="item"
                  :label="key"
                >{{ item }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="采血编号:" prop="bloodNum">
              <el-input size="mini" v-model="selectItem.bloodNum" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="条形码号:" prop="barCode">
              <el-input size="mini" v-model="selectItem.barCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采血日期:" prop="bloodTime">
              <el-date-picker
                size="mini"
                v-model="selectItem.bloodTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="样本质量:" prop="sampleQuality" v-if="selectItem.sampleQuality">
              <el-select size="mini" v-model="selectItem.sampleQuality.key" placeholder="样本质量">
                <el-option
                  v-for="(item, key, index) in dicts.SAMPLE_QUALITY"
                  :key="item"
                  :label="item"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="采血人:" prop="samplingPeople">
              <el-input size="mini" v-model="selectItem.samplingPeople" placeholder="输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="费用类型:" prop="costType" v-if="selectItem.costType">
              <el-radio-group v-model="selectItem.costType.key">
                <el-radio
                  v-for="(item, key, index) in dicts.COST_TYPE"
                  :key="item"
                  :label="key"
                >{{ item }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="送检医生:" prop="getexamineDoctor">
              <el-input size="mini" v-model="selectItem.getexamineDoctor" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="实验编号:" prop="expNum">
              <el-input size="mini" v-model="selectItem.expNum" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="免费券号:" prop="freeNum">
              <el-input size="mini" v-model="selectItem.freeNum" placeholder="输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col id="shiyan" :span="24" class="more-col">
            <el-form-item
              label="实验项目:"
              prop="projectIdList"
              class="projectIdList"
              label-width="100px"
            >
              <el-checkbox-group
                disabled
                v-model="selectItem.experimentProject"
                @change="clickCheckBox"
              >
                <el-checkbox
                  v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
                  :label="key"
                  name="type"
                >{{ item }}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" class="more-col">
            <el-form-item label="筛查备注:" class="remark" prop="remark">
              <el-input
                size="mini"
                v-model="selectItem.remark"
                type="textarea"
                placeholder="输入"
                label-width="100px"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button
          size="small"
          type="primary"
          style="padding: 6px 19px;"
          @click="onSubmit('seave')"
        >保存</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import examineManageApi from "@/api/examineManage.js";
import { initDicts } from "@/utils/commons";
import orgApi from "@/api/Org.js";
import SampleManageApi from "@/api/SampleManage.js";

export default {
  data() {
    return {
      // 转菊花
      loading: false,
      // 审核显示
      auditShow: false,
      // 点击查看
      seeShow: false,
      // 医院弹窗
      HospitalShow: false,
      dialogEdit: false,
      // 项目弹窗
      ExperimentShow: false,
      // 修改样本转菊花
      editSempelLoading: false,
      selectItem: {
        // 户口类型【农村/城镇】
        accountType: {
          key: ""
        },
        // 住址
        address: "",
        // 所属区县
        areaId: {
          key: ""
        },
        // 婴儿性别【男/女/未知】
        babySex: {
          key: ""
        },
        // 条形码号
        barCode: "",
        // 出生日期
        birthTime: "",
        // 采血编号
        bloodNum: "",
        // 采血日期
        bloodTime: "",
        // 费用类型【自费/免费】
        costType: {
          key: ""
        },
        // 父亲身份证
        dadCard: "",
        // 孕天【0-6之间】
        days: "",
        // 所属部门
        departId: {
          key: ""
        },
        // 实验编号
        expNum: "",
        // 免费劵号
        freeNum: "",
        // 送检医生
        getexamineDoctor: "",
        // 医院id
        hospitalId: {
          key: ""
        },
        // 母亲身份证
        momCard: "",
        // 母亲户籍【本地/外地】
        momCensus: {
          key: ""
        },
        // 母亲姓名
        momName: "",
        // 手机号码
        phone: "",
        // 筛查备注
        remark: "",
        // 样本质量【默认合格，基础码表】
        sampleQuality: {
          key: ""
        },
        // 采血人
        samplingPeople: "",
        // 孕周【20-50之间】
        weeks: "",
        // 婴儿体重
        weight: "",
        // 实验项目
        experimentProject: []
      },
      // 项目保存数据
      experimentItem: {
        experimentProjects: ["THA"],
        expNumList: []
      },
      // 医院保存数据
      hospitalItem: {
        areaId: {
          key: ""
        },
        departId: {
          key: ""
        },
        expNumList: [],
        hospitalId: {
          key: ""
        }
      },
      // 审核提交数据
      auditFormData: {
        checkStatus: {
          data: "",
          key: "yes"
        },
        experimentCode: "",
        experimentSwatchId: "",
        list: [],
        experimentResultMan: this.$store.state.account.user.name,
        experimentCheckMan: this.$store.state.account.user.name,
        experimentReportMan: this.$store.state.account.user.name,
        experimentResultTime: "",
        experimentCheckTime: "",
        experimentReportTime: ""
      },
      // 表格数据
      tableData: [],
      // 选中数据
      selectList: [],
      total: 0,
      // 基本数据
      basicData: {
        current: 1,
        map: {},
        model: {
          areaId: {
            key: ""
          },
          birthTime: {
            end: "",
            start: ""
          },
          departId: {
            key: ""
          },
          expNum: {
            end: "",
            start: ""
          },
          experimentCode: {
            data: "",
            key: ""
          },
          experimentDate: {
            end: "",
            start: ""
          },
          hospitalId: {
            key: ""
          },
          momName: "",
          phone: ""
        },
        order: "descending",
        size: 10,
        sort: "id"
      },
      // 字典
      dicts: {
        EXPERIMENT_CODE: {}, //实验项目
        EXPERIMENT_RESULT: {}, //实验结论
        BLOOD_STATUS: {}, //采样状态
        PAY_WAY: {}, //交付方式
        FILE_STATUS: {}, //归档状态
        COST_TYPE: {}, //费用类型
        MOM_CENSUS: {}, //母亲户籍
        SAMPLE_QUALITY: {}, //样本质量
        ACCOUNT_TYPE: {}, //户口类型
        REFUND_AUDIT: {}, //退款审核
        BABY_SEX: {} //性别
      },
      // 审核选中列表数据
      selectAuditList: [],
      // 审核列表数据
      auditList: [],
      seeData: [],
      // 市县
      orgTree: [],
      // 医院
      orgTreeC: [],
      // 部门
      orgTreeCs: [],
      // 校验
      basicDataRules: {
        "areaId.key": [
          { required: false, message: "请选择所属区县", trigger: "change" }
        ],
        "hospitalId.key": [
          { required: false, message: "请选择所属医院", trigger: "change" }
        ],
        "departId.key": [
          { required: false, message: "请选择所属部门", trigger: "change" }
        ],
        "experimentCode.key": [
          { required: true, message: "   ", trigger: "change" }
        ],
        momName: [
          { required: false, message: "请输入母亲姓名", trigger: "change" }
        ],
        phone: [
          { required: false, message: "请输入手机号码", trigger: "change" }
        ],
        weight: [{ required: false, message: "请输入体重", trigger: "change" }],
        week: [{ required: false, message: "请输入孕周", trigger: "change" }],
        day: [{ required: false, message: "请输入孕天", trigger: "change" }],
        sex: [{ required: false, message: "请选择性别", trigger: "change" }],
        samplingNumber: [
          { required: false, message: "请输入采血编号", trigger: "change" }
        ],
        barCode: [
          { required: false, message: "请输入条形码号", trigger: "change" }
        ]
      },
      editRules: {
        "areaId.key": [{ required: true, message: "必填", trigger: "change" }],
        "hospitalId.key": [
          { required: true, message: "必填", trigger: "change" }
        ],
        "departId.key": [
          { required: true, message: "必填", trigger: "change" }
        ],
        momName: [{ required: true, message: "必填", trigger: "change" }],
        phone: [
          { required: true, message: "必填", trigger: "change" },
          {
            required: true,
            pattern: /^1[3456789]\d{9}$/,
            message: "请输入正确格式的手机号",
            trigger: "blur"
          }
        ],
        weight: [
          { required: true, message: "必填", trigger: "change" },
          {
            pattern: /^[0-9]*$/,
            message: "请填写正确格式的数字",
            trigger: "change"
          },
          {
            required: true,
            validator: this.$weightNum,
            trigger: "blur",
            message: "请输入600—8000的数字"
          }
        ],
        weeks: [
          { required: true, message: "必填", trigger: "change" },
          {
            pattern: /^[0-9]*$/,
            message: "请填写正确格式的数字",
            trigger: "change"
          },
          {
            required: true,
            validator: this.$weeksNum,
            trigger: "blur",
            message: "请输入20—50的数字"
          }
        ],
        // days: [
        //   { required: true, message: "必填", trigger: "change" },
        //   {
        //     pattern: /^[0-9]*$/,
        //     message: "请填写正确格式的数字",
        //     trigger: "change"
        //   },
        //   {
        //     required: true,
        //     validator: this.$daysNum,
        //     trigger: "blur",
        //     message: "请输入0—6的数字"
        //   }
        // ],
        birthTime: [{ required: true, message: "  ", trigger: "change" }],
        bloodTime: [{ required: true, message: "  ", trigger: "change" }],
        babySex: [{ required: true, message: "  ", trigger: "change" }],
        barCode: [
          {
            required: true,
            message: "必填",
            trigger: "change"
          },
          {
            pattern: /^[0-9]*$/,
            message: "请填写正确格式的数字",
            trigger: "change"
          },
          {
            required: true,
            validator: this.$barCodeNum,
            trigger: "blur",
            message: "请输入14000000000—20999999999的数字"
          }
        ],
        costType: [{ required: true, message: "  ", trigger: "change" }],
        dadCard: [
          {
            pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
            message: "身份证号格式错误",
            trigger: "change"
          }
        ],
        momCard: [
          {
            pattern: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
            message: "身份证号格式错误",
            trigger: "change"
          }
        ],
        freeNum: [
          {
            pattern: /^[0-9]*$/,
            message: "请填写正确格式的数字",
            trigger: "change"
          },
          {
            validator: this.$freeNum,
            message: "请输入200110001—200145000的数字",
            trigger: "change"
          }
        ]
      },
      file: {},
      auditTitle: "审核",
      dateList: [],
      timeType: "birthTime",
      queryData: {
        expNum: "",
        momName: "",
        experimentValueResult: {
          key: "",
          data: ""
        }
      }
    };
  },
  computed: {
    // 模糊搜索
    tables() {
      if (this.auditList.length > 0) {
        let dataList = JSON.parse(JSON.stringify(this.auditList));
        let queryList = [];
        if (this.queryData.expNum != "") {
          let i = 0;
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "expNum") {
                if (
                  String(data[key])
                    .toLowerCase()
                    .indexOf(this.queryData.expNum) > -1
                ) {
                  queryList.push(data);
                  i++;
                }
              }
            });
          });
          if (i == 0) {
            this.$message.error("没有当前实验编号");
          }
        } else if (this.queryData.momName != "") {
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "momName") {
                if (
                  String(data[key])
                    .toLowerCase()
                    .indexOf(this.queryData.momName) > -1
                ) {
                  queryList.push(data);
                }
              }
            });
          });
        } else if (this.queryData.experimentValueResult.key != "") {
          dataList.filter(data => {
            Object.keys(data).some(key => {
              if (key == "experimentValueResult") {
                if (
                  String(data[key].key)
                    .toLowerCase()
                    .indexOf(this.queryData.experimentValueResult.key) > -1
                ) {
                  queryList.push(data);
                }
              }
            });
          });
        } else {
          queryList = JSON.parse(JSON.stringify(this.auditList));
        }
        return queryList;
      }
    }
  },
  mounted() {
    initDicts(
      [
        "EXPERIMENT_CODE",
        "EXPERIMENT_RESULT",
        "BLOOD_STATUS",
        "PAY_WAY",
        "FILE_STATUS",
        "COST_TYPE",
        "MOM_CENSUS",
        "SAMPLE_QUALITY",
        "ACCOUNT_TYPE",
        "REFUND_AUDIT",
        "BABY_SEX"
      ],
      this.dicts
    );
    this.getList(this.basicData);
    this.initOrgTree();
  },
  methods: {
    // 重置搜索
    clickResult() {
      this.queryData = {
        expNum: "",
        momName: "",
        experimentValueResult: {
          key: "",
          data: ""
        }
      };
    },
    // 设置单元格样式
    tableRowStyle({ row, rowIndex }) {
      if (row.experimentValueResult.key != "normal") {
        return { "background-color": "#baccef", color: "#606266" };
      }
    },
    // 上传文件
    onChange(file) {
      this.file = file.raw;
    },
    // 修改上传文件地址
    requestUpload(file) {
      let that = this;
      //  表单提交方式
      let FormDatas = new FormData();
      this.importLoading = true;
      FormDatas.append("file", that.file);
      examineManageApi.reportAudit
        .importSample(FormDatas)
        .then(function(res) {
          if (res.data.isSuccess || res.data.data == true) {
            that.getList(this.basicData);
          } else {
            that.$message.error(res.data.data.msg);
          }
        })
        .finally(() => (this.importLoading = false));
    },
    // 更新报告
    syncReport() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要更新报告的数据");
        return;
      }
      let dataList = [];

      this.selectList.forEach(item => {
        dataList.push(item.id);
      });
      examineManageApi.reportAudit.syncReport(dataList).then(res => {
        if (res.status == 200) {
          this.$message({
            type: "success",
            messagthie: res.statusText
          });
          this.getList(this.basicData);
        } else {
          this.$message.error(res.statusText);
        }
      });
    },
    // 操作按钮
    onSubmit(type) {
      if (type == "query") {
        this.$refs.basicForm.validate(valid => {
          if (valid) {
            if (this.timeType == "birthTime") {
              this.basicData.model.birthTime.start = this.dateList[0];
              this.basicData.model.birthTime.end = this.dateList[1];
            } else if (this.timeType == "experimentDate") {
              this.basicData.model.experimentDate.start = this.dateList[0];
              this.basicData.model.experimentDate.end = this.dateList[1];
            }
            this.getList(this.basicData);
          } else {
            return false;
          }
        });
      } else if (type == "seave") {
        // 设置选中值
        examineManageApi.reportAudit.updateSample(this.selectItem).then(res => {
          if (res.status == "200") {
            this.getList(this.basicData);
            this.dialogEdit = false;
          } else {
            this.$message.error(res.statusText);
          }
        });
      } else if (type == "reset") {
        // 如果为true则清空表单
        this.$refs["basicForm"].resetFields();
        this.basicData.model.expNum.start = "";
        this.basicData.model.expNum.end = "";
        this.dateList = [];
        this.timeType = "birthTime";
        this.basicData.model.birthTime.start = "";
        this.basicData.model.birthTime.end = "";
        this.basicData.model.experimentDate.start = "";
        this.basicData.model.experimentDate.end = "";
        this.getList(this.basicData);
      }
    },
    // 修改项目选择
    clickCheckBox(v) {
      this.selectItem.experimentProject.list = v;
    },
    // 修改样本
    clickEdit() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要修改的样本");
        return;
      }
      if (this.selectList.length > 1) {
        this.$message.error("只能选择一条数据哦");
        return;
      }
      this.editSempelLoading = true;
      setTimeout(() => {
        this.editSempelLoading = false;

        this.selectList.forEach((item, index) => {
          this.orgTree.filter(res => {
            if (res.id == item.areaId.key) {
              this.orgTreeC = res.children;
            }
          });
          this.orgTreeC.filter(res => {
            if (res.id == item.hospitalId.key) {
              this.orgTreeCs = res.children;
            }
          });
        });
        examineManageApi.reportAudit
          .getSample({
            expNum: this.selectList[0].expNum
          })
          .then(res => {
            this.selectItem = res.data.data;
            this.rowData = res.data.data;
            this.dialogEdit = true;
          });
      }, 1000);
    },
    // 根据选择市县获取医院
    clickOrgTree(v) {
      this.orgTreeC = [];
      this.orgTreeCs = [];
      this.basicData.model.hospitalId.key = "";
      this.basicData.model.departId.key = "";
      this.orgTree.filter(res => {
        if (res.id == v) {
          this.orgTreeC = res.children;
        }
      });
    },
    // 根据选择市县获取医院
    clickOrgTreeC(v) {
      this.orgTreeCs = [];
      this.basicData.model.departId.key = "";
      this.orgTreeC.filter(res => {
        if (res.id == v) {
          this.orgTreeCs = res.children;
        }
      });
    },
    // 获取基础查询
    initOrgTree() {
      orgApi.allTree({}).then(response => {
        const res = response.data;
        this.orgTree = res.data[0].children;
      });
    },
    // 点击查看
    clickSeeExpValue(v) {
      this.seeShow = true;
      let sortData = [];
      for (let key in v) {
        sortData.push(v[key]);
      }
      this.seeData = this.$keysrt(sortData, "sortValue");
    },
    // 修改结论
    clickResult() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要修改结论的数据!");
        return;
      }
      this.auditTitle = "修改结论";
      this.auditShow = true;
    },
    // 审核保存
    clickAuditSeav() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要审核的数据!");
        return;
      }
      if (this.auditTitle == "审核") {
        if (this.auditFormData.experimentCheckMan == "") {
          this.$message.error("请输入审核人姓名");
          return;
        }
        this.tijiaoList.forEach(item => {
          item.experimentResultTime = this.auditFormData.experimentResultTime;
          item.experimentCheckTime = this.auditFormData.experimentCheckTime;
          item.experimentReportTime = this.auditFormData.experimentReportTime;
          item.experimentCheckMan = this.auditFormData.experimentCheckMan;
          item.experimentReportMan = this.auditFormData.experimentReportMan;
          item.experimentResultMan = this.auditFormData.experimentResultMan;
        });
        this.auditFormData.list = this.tijiaoList;
        examineManageApi.reportAudit.auditSave(this.auditFormData).then(res => {
          if (res.status == 200) {
            this.$message({
              type: "success",
              message: res.statusText
            });
            this.auditShow = false;
            this.getList(this.basicData);
          } else {
            this.$message.error(res.statusText);
          }
        });
      } else if (this.auditTitle == "修改结论") {
        this.auditFormData.list = this.auditList;
        examineManageApi.reportAudit
          .updateExperimentResult(this.auditFormData)
          .then(res => {
            if (res.status == 200) {
              this.$message({
                type: "success",
                message: res.statusText
              });
              this.auditShow = false;
              this.getList(this.basicData);
            } else {
              this.$message.error(res.statusText);
            }
          });
      }
    },
    // 审核选中数据
    selectAuditListChanage(v) {
      this.selectAuditList = v;
    },
    // 点击审核
    clickAudit(v) {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要审核的数据!");
        return;
      }
      let numList = [];
      this.selectList.forEach((item, index) => {
        numList.push(item.expNum ? item.expNum : "");
      });

      examineManageApi.reportAudit.auditView(numList).then(res => {
        if (res.data.data) {
          this.auditList = res.data.data;
          this.auditList.forEach(item => {
            if (item.experimentResult == null) {
              item.experimentResult = {
                key: "",
                data: ""
              };
            }
          });
          this.tijiaoList = this.auditList;
          this.auditTitle = "审核";
          this.auditShow = true;
          let date =
            new Date().getFullYear().toString() +
            "-" +
            ((new Date().getMonth() + 1).toString() < 10
              ? "0" + (new Date().getMonth() + 1).toString()
              : (new Date().getMonth() + 1).toString()) +
            "-" +
            (new Date().getDate().toString() < 10
              ? "0" + new Date().getDate().toString()
              : new Date().getDate().toString());
          this.auditFormData.experimentResultTime = date;
          this.auditFormData.experimentCheckTime = date;
          this.auditFormData.experimentReportTime = date;
        } else {
          this.$message.error("暂无数据");
          return;
        }
      });
      examineManageApi.reportAudit
        .auditInfo({
          experimentSwatchId: this.selectList[0].id
        })
        .then(res => {
          let data = res.data.data;
          let date =
            new Date().getFullYear().toString() +
            "-" +
            ((new Date().getMonth() + 1).toString() < 10
              ? "0" + (new Date().getMonth() + 1).toString()
              : (new Date().getMonth() + 1).toString()) +
            "-" +
            (new Date().getDate().toString() < 10
              ? "0" + new Date().getDate().toString()
              : new Date().getDate().toString());
          this.auditFormData.experimentResultMan = data.experimentResultMan
            ? data.experimentResultMan
            : this.$store.state.account.user.name;
          this.auditFormData.experimentCheckMan = data.experimentCheckMan
            ? data.experimentCheckMan
            : this.$store.state.account.user.name;
          this.auditFormData.experimentReportMan = data.experimentReportMan
            ? data.experimentReportMan
            : this.$store.state.account.user.name;
          this.auditFormData.experimentResultTime = data.experimentResultTime
            ? data.experimentResultTime
            : date;
          this.auditFormData.experimentCheckTime = data.experimentCheckTime
            ? data.experimentCheckTime
            : date;
          this.auditFormData.experimentReportTime = data.experimentReportTime
            ? data.experimentReportTime
            : date;
        });
    },
    // 点击同步数据按钮
    clickSetSync() {
      this.SyncShow = true;
    },
    // 获取数据
    getList(data) {
      this.loading = true;
      examineManageApi.reportAudit
        .page(data)
        .then(res => {
          if (res.status === 200) {
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => (this.loading = false));
    },
    // 选中数据操作
    selectChanage(v) {
      this.selectList = v;
    },
    // 点击分页
    handleSizeChange: function(val) {
      this.basicData.size = val;
      this.getList(this.basicData);
    },
    // 选择页码
    handleCurrentChange: function(currentPage) {
      this.basicData.current = currentPage;
      this.getList(this.basicData);
    }
  }
};
</script>

<style lang="less">
.flex {
  display: flex;
  align-items: center;
  justify-content: center;
}

#reportAudit {
  .el-form-item__content,
  .el-date-editor,
  .el-select,
  .el-textarea {
    width: 100% !important;
  }
  .buttom {
    width: 100%;
    .flex;
  }
  .info-item {
    .el-form-item__content {
      width: 70%;
      .el-select {
        width: 100%;
      }
    }
  }

  .mores {
    .flex;
    justify-content: flex-start;

    .more-title {
      font-size: 12px;
      font-family: SourceHanSansSC;
      font-weight: 400;
      color: rgb(153, 153, 153);
      font-style: normal;
      letter-spacing: 0px;
      line-height: 20px;
      text-decoration: none;
      margin-right: 1rem;
    }
  }
}
</style>
